package com.sx.pipeline.ui.task.approve.frag

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.noober.background.view.BLTextView
import com.sx.pipeline.R
import com.sx.pipeline.app.config.ReleaseTaskType
import com.sx.pipeline.arouth.RouteManager
import com.sx.pipeline.repos.http.res.ReleaseTaskVo
import com.sx.pipeline.ui.task.entity.ReleaseTaskListVO

/**
 * @Author：YY
 * @Date：2022/2/10
 * @Describe: 我参与的列表适配器
 */
class ApproveTaskListAdapter(
) : BaseQuickAdapter<ReleaseTaskVo, BaseViewHolder>(
    R.layout.item_operating_unit_release
) {
    /**
     * 拒绝任务
     */
    var rejectTaskCallback: ((Int) -> Unit)? = null

    /**
     * 同意任务
     */
    var agreeTaskCallback: ((Int,String) -> Unit)? = null
    override fun convert(holder: BaseViewHolder, item: ReleaseTaskVo) {
        //工作性质
        holder.setText(R.id.tv_nature, item.nature)
        //任务时间
        holder.setText(R.id.tv_start_time, item.startTime)
        //任务标题
        holder.setText(R.id.tv_title, item.title)
        //项目名称
        holder.setText(R.id.tv_project_name, "项目名称：" + item.name)
        //工作量
        holder.setText(R.id.tv_work_load, "工作量：" + item.workload + item.unit)
        //施工地点
        holder.setText(R.id.tv_release_address, "施工地点：" + item.addressDetail)
        //现场负责人
        holder.setText(R.id.tv_release_principal, "现场负责人：" + item.contact)

        //任务状态
        when (item.status) {
            0 -> holder.setText(R.id.tv_status, R.string.txt_pending_review)
            1 -> holder.setText(R.id.tv_status, R.string.txt_passed)
            2 -> holder.setText(R.id.tv_status, R.string.txt_rejected)
        }
        when (item.status) {
            //待审核
            0 -> {
                holder.setText(R.id.tv_delete, context.getString(R.string.txt_denial_task))
                holder.setText(R.id.tv_action, context.getString(R.string.txt_agree_task))
                holder.setVisible(R.id.tv_delete, true)
                holder.setVisible(R.id.tv_action, true)
            }
            1 -> {
                holder.setGone(R.id.tv_delete, true)
                holder.setGone(R.id.tv_action, true)
            }
            2 -> {
                holder.setText(R.id.tv_action, context.getString(R.string.txt_rejection_reason))
                holder.setVisible(R.id.tv_delete, false)
                holder.setVisible(R.id.tv_action, true)
            }
        }

        holder.getView<BLTextView>(R.id.tv_action).setOnClickListener {
            when (item.status) {
                //同意任务
                0 -> agreeTaskCallback?.invoke(item.id,item.name)
                //查看原因
                2 -> RouteManager.Mine.intentToTaskApproveDetail(item.id)

            }
        }
        holder.getView<BLTextView>(R.id.tv_delete).setOnClickListener {
            when (item.status) {
                //拒绝任务
                0 -> rejectTaskCallback?.invoke(item.id)
            }
        }
    }
}